package aaa;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import org.eclipse.jface.dialogs.MessageDialog;

public class V extends JFrame {
	 
	    private int length;
 private static final long serialVersionUID = 8665272220673200148L;
 
 private JPanel pnlMain = new JPanel();
 private JTextField txfInputText = new JTextField();
 private JTextArea txaOutputText = new JTextArea();
 private JButton btnStart = new JButton("Start");
 private JScrollPane jScrollPane = new JScrollPane(txaOutputText);
 
 public V() {
  setSize(700, 400); //                    
  setVisible(true); //            JFrame
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //                 
              //                 
  //setTitle(title);
  
  txfInputText.setBounds(25, 25, 500, 25);
  btnStart.setBounds(550, 25, 100, 25);
  jScrollPane.setBounds(25, 75, 625, 250);

  pnlMain.add(txfInputText);
  pnlMain.add(btnStart);
  pnlMain.add(jScrollPane);

  pnlMain.setBackground(Color.WHITE);
  pnlMain.setLayout(null);
  add(pnlMain);

  
  
  
  btnStart.addActionListener(new ActionListener() { //                 
   private int[] array;

public void actionPerformed(ActionEvent arg0) {
	   String c =txfInputText.getText();
	   c.trim();
	   String[] c1=c.split(" ");
	   int[] vvid=new int[100];
	   
	   int i=0;
		for(String token:c1){
			vvid[i]=Integer.parseInt(token);
			
			//txaOutputText.append(token+"\n");
			i++;}
		int[] mass=new int[i];
		for(int r=0;r<i;r++)
		{
			mass[r]=vvid[r];
		}
	
		   
		   
	
		
		sort(mass);
		 
	   //txaOutputText.append("iteration 567 "+c+"\n");
	  
   }

	/** Quick Sort function **/
int ll=0;
   public  void sort(int[] arr)

   {

       quickSort(arr, 0, arr.length - 1);

   }

   /** Quick sort function **/

   public  void quickSort(int arr[], int low, int high) 

   {

       int i = low, j = high;

       int temp;

       int pivot = arr[(low + high) / 2];



       /** partition **/

       while (i <= j) 

       {

           while (arr[i] < pivot)

               i++;

           while (arr[j] > pivot)

               j--;

           if (i <= j) 

           {

               /** swap **/

               temp = arr[i];

               arr[i] = arr[j];

               arr[j] = temp;



               i++;

               j--;

           }

       }
       txaOutputText.append("Ітерація "+ll+": ");
       for (int k = 0; k < arr.length; k++)
			 txaOutputText.append(""+arr[k]+" ");
       txaOutputText.append("\n");
       /** recursively sort lower half **/
        ll++;
       if (low < j)

           quickSort(arr, low, j);

       /** recursively sort upper half **/

       if (i < high)

           quickSort(arr, i, high);

   }


  });
 }

 public static void main(String[] args) {
  new V();
 }
}